#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN=1010,MAXM=1e6+10,INF=0x7fffffff;
int n,m,d,head[MAXN],cnt,tot,num[30][30],idx[MAXN],ans;
struct edge
{
	int v,next,val;
}e[MAXM];
struct point
{
	int x,y,val;
}p[MAXN];
queue<int>q;
void addedge(int x,int y,int z)
{
	e[cnt]=(edge){y,head[x],z};
	head[x]=cnt++;
	return;
}
int dis(int x1,int y1,int x2,int y2)
{
	return abs(x1-x2)+abs(y1-y2);
}
void bfs()
{
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=head[u];~i;i=e[i].next)
		{
			int v=e[i].v;
			if(!e[i].val||idx[v])continue;
			idx[v]=idx[u]+1;
			q.push(v);
		}
	}
	return;
}
int dfs(int u,int _min)
{
	if(u==(tot<<1|1))return _min;
	int ret=0;
	for(int i=head[u];~i;i=e[i].next)
	{
		int v=e[i].v;
		if(!e[i].val||idx[v]!=idx[u]+1)continue;
		int k=dfs(v,min(_min-ret,e[i].val));
		e[i].val-=k;
		e[i^1].val+=k;
		ret+=k;
		if(ret==_min)break;
	}
	return ret;
}
int main()
{
	memset(head,-1,sizeof(head));
	scanf("%d%d%d",&n,&m,&d);
	for(int i=1;i<=n;++i)
	{
		char temp[30];
		scanf("%s",temp+1);
		for(int j=1;j<=m;++j)
			if(temp[j]-'0'>0)
			{
				num[i][j]=++tot;
				p[tot]=(point){i,j,temp[j]-'0'};
			}
	}
	for(int i=1;i<=n;++i)
	{
		char temp[30];
		scanf("%s",temp+1);
		for(int j=1;j<=m;++j)
			if(temp[j]=='L')
			{
				++ans;
				addedge(0,(num[i][j]<<1)-1,1);
				addedge((num[i][j]<<1)-1,0,0);
			}
	}
	for(int i=1;i<=tot;++i)
	{
		addedge((i<<1)-1,i<<1,p[i].val);
		addedge(i<<1,(i<<1)-1,0);
		if(p[i].x<=d||p[i].y<=d||n-p[i].x+1<=d||m-p[i].y+1<=d)
		{
			addedge(i<<1,tot<<1|1,INF);
			addedge(tot<<1|1,i<<1,0);
		}
		for(int j=i+1;j<=tot;++j)
			if(dis(p[i].x,p[i].y,p[j].x,p[j].y)<=d)
			{
				addedge(i<<1,(j<<1)-1,INF);
				addedge((j<<1)-1,i<<1,0);
				addedge(j<<1,(i<<1)-1,INF);
				addedge((i<<1)-1,j<<1,0);
			}
	}
	while(1)
	{
		memset(idx,0,sizeof(idx));
		q.push(0);
		idx[0]=1;
		bfs();
		if(!idx[tot<<1|1])break;
		ans-=dfs(0,INF);
	}
	printf("%d\n",ans);
	return 0;
}
